/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.composite.helper;

import org.eclipse.uml2.uml.Abstraction;
import org.eclipse.uml2.uml.Dependency;
import org.eclipse.uml2.uml.Realization;
import org.eclipse.uml2.uml.Usage;

import com.cea.papyrus.core.IPapyrusUIConstants;
import com.cea.papyrus.core.helper.DefaultModelerHelper;
import com.cea.papyrus.core.helper.IGraphElementHelper;
import com.cea.papyrus.core.helper.NodeHelper;
import com.cea.papyrus.core.pseudoelement.InstanceSpecificationLink;
import com.cea.papyrus.diagram.classdiagram.helper.EdgeAbstractionHelper;
import com.cea.papyrus.diagram.classdiagram.helper.EdgeDependencyHelper;
import com.cea.papyrus.diagram.classdiagram.helper.EdgeGeneralizationHelper;
import com.cea.papyrus.diagram.classdiagram.helper.EdgeGraphLinkHelper;
import com.cea.papyrus.diagram.classdiagram.helper.EdgeRealizationHelper;
import com.cea.papyrus.diagram.classdiagram.helper.EdgeUsageHelper;
import com.cea.papyrus.diagram.classdiagram.helper.NodeCommentHelper;
import com.cea.papyrus.diagram.classdiagram.helper.NodeConstraintHelper;
import com.cea.papyrus.diagram.composite.pseudoelement.RoleBinding;

/**
 * Main factory for the composite diagram that keeps correspondance between
 * uml elements and their associated factory.
 */
public class CompositeModelerHelper extends DefaultModelerHelper {

	/**
	 * singleton instance of this class.
	 */
	private static CompositeModelerHelper EINSTANCE; 
	
	/**
	 * set of uml elements that can be created in this diagram.
	 */
	protected final Class<?> elementTypes[] = {
			org.eclipse.uml2.uml.Element.class,
			org.eclipse.uml2.uml.Comment.class,
			org.eclipse.uml2.uml.Constraint.class,
			org.eclipse.uml2.uml.Class.class,
			org.eclipse.uml2.uml.Port.class,
			org.eclipse.uml2.uml.Property.class,
			org.eclipse.uml2.uml.Collaboration.class,
			org.eclipse.uml2.uml.CollaborationUse.class,
			org.eclipse.uml2.uml.Interface.class,
			org.eclipse.uml2.uml.InstanceSpecification.class,
			org.eclipse.uml2.uml.Slot.class,
			
			// edges
			org.eclipse.uml2.uml.Generalization.class,
			org.eclipse.uml2.uml.Connector.class,
			com.cea.papyrus.core.pseudoelement.GraphicalLink.class,
			RoleBinding.class,
			InstanceSpecificationLink.class,
			Dependency.class,
			Abstraction.class,
			Usage.class,
			Realization.class
			
	};
	
	/**
	 * set of factories that correspond to the precedent uml types.
	 */
	protected final IGraphElementHelper nodeFactory[] = {
			new NodeHelper(),
			new NodeCommentHelper(),
			new NodeConstraintHelper(),
			new NodeClassHelper(),
			new NodePortHelper(),
			new NodePropertyHelper(),
			new NodeCollaborationHelper(),
			new NodeCollaborationUseHelper(),
			new NodeInterfaceHelper(),
			new NodeInstanceSpecificationClassHelper(),
			new CompositeSlotHelper(),
			// edges factory
			new EdgeGeneralizationHelper(),
			new EdgeConnectorHelper(),
			new EdgeGraphLinkHelper(),
			new EdgeRoleBindingHelper(),
			new CompositeEdgeInstanceSpecificationHelper(),
			new EdgeDependencyHelper(),
			new EdgeAbstractionHelper(),
			new EdgeUsageHelper(),
			new EdgeRealizationHelper()
			
	};
	
	/**
	 * Create the factories for model elements.
	 */
	public CompositeModelerHelper() {
		// CreateFactories
		for(int i=0; i<elementTypes.length; i++){
			creationFactoryMap.put( elementTypes[i], nodeFactory[i]);
		}		
	}
	
	/**
	 * Returns the singleton instance of this class.
	 * 
	 * @return this instance of ModelResourceManager
	 */
	public static CompositeModelerHelper getInstance(){
		if (EINSTANCE == null) {
			EINSTANCE = new CompositeModelerHelper();
		}
		return EINSTANCE;
	}
	
	/* (non-Javadoc)
	 * @see com.cea.papyrus.common.factories.IModelerFactory#getId()
	 */
	/**
	 * 
	 * 
	 * @return 
	 */
	@Override
	public String getId() {
		return IPapyrusUIConstants.COMPOSITE_STRUCTURE_DIAGRAM;
	}

}
